package com.fps.webshop.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

@Configuration
public class CorsConfig {

    @Bean
    public CorsWebFilter corsWebFilter() {
        UrlBasedCorsConfigurationSource urlBased = new UrlBasedCorsConfigurationSource();
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        //允许跨域访问的请求头
        corsConfiguration.addAllowedHeader("*");
        //允许跨域访问的请求方法
        corsConfiguration.addAllowedMethod("*");
        //允许跨域访问的域名
        corsConfiguration.addAllowedOrigin("*");
        //是否支持安全证书，是否允许发送Cookie
        corsConfiguration.setAllowCredentials(true);
        urlBased.registerCorsConfiguration("/**", corsConfiguration);
        return new CorsWebFilter(urlBased);
    }
}
